@extends('layout.default')

@section('layout.content')
<div class="space-32"></div>
  <div class="row">
    <div class="col-xs-12">
      <form class="form-horizontal" id="role-create" autocomplete="off">        
        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="isparent"> <b><span class="red">*</span> 菜单类型：</b>
          </label>
          <div class="col-sm-4 checkbox">
            <label>
              <input name="isparent" type="checkbox" value="1" class="ace ace-checkbox-2 isparent"
                     {{$permission->parent == 0?'checked':''}} disabled="disabled"/>
              <span class="lbl"> 一级菜单</span>
            </label>
          </div>
        </div>
        <div class="form-group parentlist" style="{{$permission->parent == 0?'display:none;':'display:block;'}}">
          <label class="col-sm-4 control-label no-padding-right" for="parent"> 父级菜单：</label>
          <div class="col-sm-3">
            <select name="parent" class="form-control parent">
              <option {{$permission->parent == 0?'selected':''}} disabled>请选择父级菜单</option>
              @foreach($parents as $key=>$parent)
                <option value="{{$parent->id}}"
                        data-controller="{{$parent->controller}}" {{$permission->parent == $parent->id?'selected':''}} {{$permission->id == $parent->id?'disabled':''}}>{{$parent->title}}</option>
              @endforeach
            </select>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="title"> <b><span class="red">*</span> 菜单名称：</b>
          </label>
          <div class="col-sm-4">
            <input type="text" value="{{$permission->title}}" class="form-control" id="title" name="title"
                   placeholder="菜单名称"/>
          </div>
        </div>        
        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="controller"> <b><span class="red">*</span>
              控制器：</b> </label>
          <div class="col-sm-4">
            <input type="text" value="{{$permission->controller}}" class="form-control controller" id="controller"
                   name="controller" placeholder="控制器" />
          </div>
        </div>
        <div class="form-group action" style="{{$permission->parent==0?'display: none;':'display: block;'}}">
          <label class="col-sm-4 control-label no-padding-right" for="action"> 模块：</label>
          <div class="col-sm-4">
            <input type="text" value="{{$permission->action}}" class="form-control" id="action" name="action"
                   placeholder="模块"/>
          </div>
        </div>

        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="name"> <b><span class="red">*</span> 导航参数：</b>
          </label>
          <div class="col-sm-4">
            <input type="text" value="{{$permission->name}}" class="form-control" id="name" name="name"
                   placeholder="菜单参数"/>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="status"> <b><span class="red">*</span>属性：</b> </label>
          <div class="col-sm-6">
            <div class="radio">
              <label class="inline no-padding-left">
                <input name="status" type="checkbox" value="1" class="ace ace-checkbox-2 input-lg" {{$permission->status==1?'checked':''}}>
                <span class="lbl"> 可视菜单</span>
              </label>
              <label class="inline">
                <input name="status" type="checkbox" value="0" class="ace ace-checkbox-2 input-lg" {{$permission->status==0?'checked':''}}>
                <span class="lbl"> 隐藏菜单</span>
              </label>
            </div>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="status"> <b><span class="red">*</span>是否有效：</b> </label>
          <div class="col-sm-6">
            <div class="radio">
              <label class="inline no-padding-left">
                <input name="using" type="checkbox" value="1" class="ace ace-checkbox-2 input-lg" {{$permission->using==1?'checked':''}}>
                <span class="lbl"> 有效</span>
              </label>
              <label class="inline">
                <input name="using" type="checkbox" value="0" class="ace ace-checkbox-2 input-lg" {{$permission->using==0?'checked':''}}>
                <span class="lbl"> 无效</span>
              </label>
            </div>
          </div>
        </div>

        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="icon"> 图标：</label>
          <div class="col-sm-3">
            <input type="text" value="{{$permission->icon}}" class="form-control" id="icon" name="icon"
                   placeholder="图标"/>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right" for="order"> 排序：</label>
          <div class="col-sm-2">
            <input type="text" value="{{$permission->order}}" class="form-control" id="order" name="order"
                   placeholder="排序"/>
          </div>
        </div>


        <div class="form-group">
          <label class="col-sm-4 control-label no-padding-right"> </label>
          <div class="col-sm-4">
            <button type="button" class="btn btn-primary submit">
              <i class="ace-icon fa fa-check"></i>
              <span class="">确定</span>
            </button>
          </div>
        </div>

      </form>
    </div>
  </div>

@stop

@section('javascript')
<script type="text/javascript">
$(function () {

    $("input:checkbox[name='status']").on('click', function(e) {
      $("input:checkbox[name='status']").not(this).attr("checked", false);
    });

    $("input:checkbox[name='using']").on('click', function(e) {
      $("input:checkbox[name='using']").not(this).attr("checked", false);
    });

    $(".isparent").on('click', function () {
        var that = $(this);
        if (that.is(":checked")) {
            $(".parentlist").css("display", "none");
            $(".controller").attr("readonly", false);
            $(".action").css("display", "none");
            $(".action-label").html("模块：");
        } else {
            $(".parentlist").css("display", "block");
            $(".controller").attr("readonly", true);
            $(".action").css("display", "block");
            $(".action-label").html('<b><span class="red">*</span> 模块：</b>');
        }
    });

    $(".parent").on('change', function () {
        var that = $(this);
        $(".controller").attr("value", that.find("option:selected").data('controller'));
    });

    $('.submit').on('click', function () {
        var uri = '{{route('system.permission.update', $permission->id)}}';
        $.post(uri, {
            '_token': $("input[name='_token']").attr('value'),
            '_method':'put',
            'isparent': $("input[name='isparent']:checked").val(),
            'parent': $("select[name='parent']").val(),
            'title': $("input[name='title']").val(),
            'controller': $("input[name='controller']").val(),
            'action': $("input[name='action']").val(),
            'name': $("input[name='name']").val(),
            'status': $("input:checkbox[name='status']:checked").val(),
            'using': $("input:checkbox[name='using']:checked").val(),
            'icon': $("input[name='icon']").val(),
            'order': $("input[name='order']").val(),
            'is_submit': true
        }, function (data) {
            layer.msg(data.message, {time:1000, shift: -1}, function () {
                if (data.status === true && data.url != null) {
                    $(window).attr('location', data.url);
                }
            });

        }, 'json').error(function (data) {
            layer.msg(data.responseJSON.message);
        });

    });


});
</script>
@stop